set.seed(18041993)

using <- function(...) {
    libs <- unlist(list(...))
    req <- unlist(lapply(libs, require, character.only = TRUE))
    need <- libs[req == FALSE]
    if (length(need) > 0) {
        install.packages(need)
        lapply(need, require, character.only = TRUE)
    }
}


using("dplyr", "ggplot2", "ggpubr", "rstatix", "NCmisc", "car", "lme4", "DHARMa",
    "emmeans", "performance", "sjPlot", "rphylopic", "jpeg", "flexplot", "report",
    "broom", "ggfortify", "MASS", "jtools", "svglite", "multcomp", "vegan", "showtext",
    "formatR")

rm(list = ls())

Prepare modeling data.frames

load("../../Results/ECTOTHERM_results/results_all_ecto2.Rda")
res_ecto_stats <- results_all

# Get yearly values
res_ecto_stats$Forage_year <- res_ecto_stats$Forage/res_ecto_stats$Year
res_ecto_stats$Bask_year <- res_ecto_stats$Bask/res_ecto_stats$Year
res_ecto_stats$Fecundity_year <- res_ecto_stats$Fecundity/res_ecto_stats$Year
res_ecto_stats$Clutches_year <- res_ecto_stats$Clutches/res_ecto_stats$Year

# Rename values
res_ecto_stats$Species[res_ecto_stats$Species == "Ihor"] <- "I. horvathi"
res_ecto_stats$Species[res_ecto_stats$Species == "Pmur"] <- "P. muralis"

res_ecto_stats$Sintopy[res_ecto_stats$Sintopy == "sint"] <- "Sintopy"
res_ecto_stats$Sintopy[res_ecto_stats$Sintopy == "aloPmur"] <- "Muralis allotopy"
res_ecto_stats$Sintopy[res_ecto_stats$Sintopy == "aloIhor"] <- "Horvathi allotopy"


# Turn to factor
res_ecto_stats$Locality <- as.factor(res_ecto_stats$Locality)
res_ecto_stats$Sintopy <- as.factor(res_ecto_stats$Sintopy)
res_ecto_stats$Species <- as.factor(res_ecto_stats$Species)


res_ecto_stats <- res_ecto_stats %>%
    rename(Loc_type = Sintopy)


res_ecto_stats <- res_ecto_stats[, c("Elevation", "Loc_type", "Species", "MeanTALOC",
    "MeanRHLOC", "Solar", "NO_Snow", "egg_dev", "LifeSpan", "Years_repro", "Bask_year",
    "Forage_year", "Fecundity_year")]

head(res_ecto_stats)
##   Elevation         Loc_type     Species MeanTALOC MeanRHLOC    Solar  NO_Snow
## 1  237.8280          Sintopy I. horvathi 14.555508  67.54956 25.63949 5650.208
## 2  945.6031 Muralis allotopy I. horvathi  8.673618  84.47199 39.68655 4750.208
## 3  377.6037          Sintopy I. horvathi 12.335269  66.66661 27.52628 5479.042
## 4 1052.0754          Sintopy I. horvathi  9.401028  79.55288 38.91069 4894.500
## 5  577.6978 Muralis allotopy I. horvathi 10.966352  79.44083 36.43622 5298.875
## 6  830.2592 Muralis allotopy I. horvathi  8.865953  76.12646 36.58389 5134.167
##   egg_dev LifeSpan Years_repro Bask_year Forage_year Fecundity_year
## 1      35        7           4  1821.857    463.2857       1.428571
## 2      59        8           2  1521.500    309.6250       0.500000
## 3      39        7           3  1966.571    461.4286       1.428571
## 4      51        8           3  1575.500    341.1250       0.750000
## 5      50        8           3  1501.500    339.3750       0.750000
## 6      53        8           3  1562.750    336.8750       0.500000
str(res_ecto_stats)
## 'data.frame':    30 obs. of  13 variables:
##  $ Elevation     : num  238 946 378 1052 578 ...
##  $ Loc_type      : Factor w/ 3 levels "Horvathi allotopy",..: 3 2 3 3 2 2 3 1 1 2 ...
##  $ Species       : Factor w/ 2 levels "I. horvathi",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ MeanTALOC     : num  14.56 8.67 12.34 9.4 10.97 ...
##  $ MeanRHLOC     : num  67.5 84.5 66.7 79.6 79.4 ...
##  $ Solar         : num  25.6 39.7 27.5 38.9 36.4 ...
##  $ NO_Snow       : num  5650 4750 5479 4894 5299 ...
##  $ egg_dev       : num  35 59 39 51 50 53 51 66 45 51 ...
##  $ LifeSpan      : num  7 8 7 8 8 8 8 9 8 8 ...
##  $ Years_repro   : int  4 2 3 3 3 3 4 2 4 3 ...
##  $ Bask_year     : num  1822 1522 1967 1576 1502 ...
##  $ Forage_year   : num  463 310 461 341 339 ...
##  $ Fecundity_year: num  1.43 0.5 1.43 0.75 0.75 ...
## Microclimate analysis table

loc_stats <- res_ecto_stats %>%
    distinct(MeanTALOC, .keep_all = TRUE)

Models and plots for elevation, species and sintopy analysis

Mean Temp at location of animal

shiny test

##   Elevation         Loc_type     Species MeanTALOC MeanRHLOC    Solar  NO_Snow
## 1  237.8280          Sintopy I. horvathi 14.555508  67.54956 25.63949 5650.208
## 2  945.6031 Muralis allotopy I. horvathi  8.673618  84.47199 39.68655 4750.208
## 3  377.6037          Sintopy I. horvathi 12.335269  66.66661 27.52628 5479.042
## 4 1052.0754          Sintopy I. horvathi  9.401028  79.55288 38.91069 4894.500
## 5  577.6978 Muralis allotopy I. horvathi 10.966352  79.44083 36.43622 5298.875
## 6  830.2592 Muralis allotopy I. horvathi  8.865953  76.12646 36.58389 5134.167
##   egg_dev LifeSpan Years_repro Bask_year Forage_year Fecundity_year
## 1      35        7           4  1821.857    463.2857       1.428571
## 2      59        8           2  1521.500    309.6250       0.500000
## 3      39        7           3  1966.571    461.4286       1.428571
## 4      51        8           3  1575.500    341.1250       0.750000
## 5      50        8           3  1501.500    339.3750       0.750000
## 6      53        8           3  1562.750    336.8750       0.500000
Shiny applications not supported in static R Markdown documents
# check data distribution
gghistogram(loc_stats$MeanTALOC, bins = 15)

ggboxplot(loc_stats$MeanTALOC)

# Check lm model
lm_MeanTALOC <- lm(MeanTALOC ~ Elevation + Loc_type, data = loc_stats)
lm_MeanTALOC_int <- lm(MeanTALOC ~ Elevation * Loc_type, data = loc_stats)

AIC(lm_MeanTALOC, lm_MeanTALOC_int)
##                  df      AIC
## lm_MeanTALOC      5 29.31994
## lm_MeanTALOC_int  7 31.00826
compare.fits(MeanTALOC ~ Elevation | Loc_type, data = loc_stats, lm_MeanTALOC, lm_MeanTALOC_int)

# Get summary and p values
summary(lm_MeanTALOC)
## 
## Call:
## lm(formula = MeanTALOC ~ Elevation + Loc_type, data = loc_stats)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.62319 -0.38025 -0.02903  0.27615  0.92012 
## 
## Coefficients:
##                            Estimate Std. Error t value Pr(>|t|)    
## (Intercept)              14.1146391  0.5812257  24.284 6.60e-11 ***
## Elevation                -0.0054589  0.0005167 -10.564 4.26e-07 ***
## Loc_typeMuralis allotopy -0.2500794  0.3841958  -0.651   0.5285    
## Loc_typeSintopy           0.8190153  0.4038880   2.028   0.0675 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.538 on 11 degrees of freedom
## Multiple R-squared:  0.9468, Adjusted R-squared:  0.9322 
## F-statistic:  65.2 on 3 and 11 DF,  p-value: 2.722e-07
# Plot

lm_Plot_eTemp <- lm(MeanTALOC ~ Elevation, data = loc_stats)

MeanTemp_plot <- visualize(lm_Plot_eTemp, MeanTALOC ~ Elevation, plot = "model") +
    scale_color_manual(values = c("black")) + theme_classic() + labs_pubr() + labs(title = NULL,
    y = "Mean temperature (°C)", x = NULL) + theme(legend.position = "null")

MeanTemp_plot

# Check model fit, residuals etc.

autoplot(lm_MeanTALOC) + theme_classic()

shapiro.test(residuals(lm_MeanTALOC))
## 
##  Shapiro-Wilk normality test
## 
## data:  residuals(lm_MeanTALOC)
## W = 0.94825, p-value = 0.4972

Mean relative humidity

# check data distribution
gghistogram(loc_stats$MeanRHLOC, bins = 15)

ggboxplot(loc_stats$MeanRHLOC)

# Check lm model first

lm_MeanRHLOC <- lm(MeanRHLOC ~ Elevation + Loc_type, data = loc_stats)

lm_MeanRHLOC_int <- lm(MeanRHLOC ~ Elevation * Loc_type, data = loc_stats)

compare.fits(MeanRHLOC ~ Elevation | Loc_type, data = loc_stats, lm_MeanRHLOC, lm_MeanRHLOC_int)

AIC(lm_MeanRHLOC, lm_MeanRHLOC_int)
##                  df      AIC
## lm_MeanRHLOC      5 77.75286
## lm_MeanRHLOC_int  7 79.55719
# Get summary and p values
summary(lm_MeanRHLOC)
## 
## Call:
## lm(formula = MeanRHLOC ~ Elevation + Loc_type, data = loc_stats)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.3674 -1.8245  0.2331  2.3209  3.1476 
## 
## Coefficients:
##                           Estimate Std. Error t value Pr(>|t|)    
## (Intercept)              64.994519   2.920674  22.253  1.7e-10 ***
## Elevation                 0.014790   0.002597   5.696 0.000139 ***
## Loc_typeMuralis allotopy  3.219854   1.930594   1.668 0.123539    
## Loc_typeSintopy          -1.232829   2.029548  -0.607 0.555891    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.704 on 11 degrees of freedom
## Multiple R-squared:  0.8282, Adjusted R-squared:  0.7814 
## F-statistic: 17.68 on 3 and 11 DF,  p-value: 0.0001618
# Plot

lm_plot_eHum <- lm(MeanRHLOC ~ Elevation, data = loc_stats)

Mean_humid <- visualize(lm_plot_eHum, MeanRHLOC ~ Elevation, plot = "model") + scale_color_manual(values = c("black")) +
    theme_classic() + labs_pubr() + labs(title = NULL, y = "Mean humidity", x = NULL) +
    theme(legend.position = "null")

Mean_humid

# Check model fit, residuals etc.

autoplot(lm_MeanRHLOC) + theme_classic()

shapiro.test(residuals(lm_MeanRHLOC))
## 
##  Shapiro-Wilk normality test
## 
## data:  residuals(lm_MeanRHLOC)
## W = 0.91829, p-value = 0.1814

Mean solar radiation

# check data distribution
gghistogram(loc_stats$Solar, bins = 5)

ggboxplot(loc_stats$Solar)

# Check lm model first

lm_Solar <- lm(Solar ~ Elevation + Loc_type, data = loc_stats)
lm_Solar_int <- lm(Solar ~ Elevation * Loc_type, data = loc_stats)

compare.fits(Solar ~ Elevation | Loc_type, data = loc_stats, lm_Solar, lm_Solar_int)

AIC(lm_Solar, lm_Solar_int)
##              df      AIC
## lm_Solar      5 65.70929
## lm_Solar_int  7 59.61318
anova(lm_Solar, lm_Solar_int)
## Analysis of Variance Table
## 
## Model 1: Solar ~ Elevation + Loc_type
## Model 2: Solar ~ Elevation * Loc_type
##   Res.Df    RSS Df Sum of Sq      F  Pr(>F)  
## 1     11 36.022                              
## 2      9 18.376  2    17.646 4.3211 0.04837 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Get summary and p values
summary(lm_Solar_int)  #AIC delta <4, include interaction
## 
## Call:
## lm(formula = Solar ~ Elevation * Loc_type, data = loc_stats)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.8615 -0.7580  0.0894  0.4437  2.6319 
## 
## Coefficients:
##                                     Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                        28.606198   2.334521  12.254 6.44e-07 ***
## Elevation                           0.009192   0.002193   4.192  0.00234 ** 
## Loc_typeMuralis allotopy            4.378561   3.112470   1.407  0.19307    
## Loc_typeSintopy                    -6.323805   2.766069  -2.286  0.04807 *  
## Elevation:Loc_typeMuralis allotopy -0.003747   0.003622  -1.034  0.32790    
## Elevation:Loc_typeSintopy           0.006400   0.003121   2.050  0.07056 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.429 on 9 degrees of freedom
## Multiple R-squared:  0.9329, Adjusted R-squared:  0.8956 
## F-statistic: 25.01 on 5 and 9 DF,  p-value: 5.007e-05
# Plot


Mean_solar <- visualize(lm_Solar_int, Solar ~ Elevation + Loc_type, plot = "model") +
    scale_color_manual(values = c("firebrick", "gold", "navyblue")) + theme_classic() +
    labs_pubr() + labs(title = NULL, y = "Mean solar radiation", x = NULL) + theme(legend.position = "null")

Mean_solar

# Check model fit, residuals etc.

autoplot(lm_Solar) + theme_classic()

shapiro.test(residuals(lm_Solar))
## 
##  Shapiro-Wilk normality test
## 
## data:  residuals(lm_Solar)
## W = 0.91047, p-value = 0.1377
# Check comparisons

summary(glht(lm_Solar_int, linfct = mcp(Loc_type = "Tukey")))
## 
##   Simultaneous Tests for General Linear Hypotheses
## 
## Multiple Comparisons of Means: Tukey Contrasts
## 
## 
## Fit: lm(formula = Solar ~ Elevation * Loc_type, data = loc_stats)
## 
## Linear Hypotheses:
##                                           Estimate Std. Error t value Pr(>|t|)
## Muralis allotopy - Horvathi allotopy == 0    4.379      3.112   1.407  0.37564
## Sintopy - Horvathi allotopy == 0            -6.324      2.766  -2.286  0.10847
## Sintopy - Muralis allotopy == 0            -10.702      2.537  -4.218  0.00541
##                                             
## Muralis allotopy - Horvathi allotopy == 0   
## Sintopy - Horvathi allotopy == 0            
## Sintopy - Muralis allotopy == 0           **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## (Adjusted p values reported -- single-step method)

Days without snow

# check data distribution
gghistogram(loc_stats$NO_Snow, bins = 50)

ggboxplot(loc_stats$NO_Snow)

# Check lm model first

lm_NO_Snow <- lm(NO_Snow ~ Elevation + Loc_type, data = loc_stats)
lm_NO_Snow_int <- lm(NO_Snow ~ Elevation * Loc_type, data = loc_stats)

compare.fits(NO_Snow ~ Elevation | Loc_type, data = loc_stats, lm_NO_Snow, lm_NO_Snow_int)

AIC(lm_NO_Snow, lm_NO_Snow_int)
##                df      AIC
## lm_NO_Snow      5 188.9979
## lm_NO_Snow_int  7 191.8064
# Get summary and p values
summary(lm_NO_Snow)
## 
## Call:
## lm(formula = NO_Snow ~ Elevation + Loc_type, data = loc_stats)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -147.40  -41.31  -14.50   61.21  191.42 
## 
## Coefficients:
##                           Estimate Std. Error t value Pr(>|t|)    
## (Intercept)              5824.6413   119.1022  48.905 3.21e-14 ***
## Elevation                  -1.0529     0.1059  -9.944 7.82e-07 ***
## Loc_typeMuralis allotopy   48.4005    78.7277   0.615    0.551    
## Loc_typeSintopy            89.2488    82.7629   1.078    0.304    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 110.2 on 11 degrees of freedom
## Multiple R-squared:  0.9368, Adjusted R-squared:  0.9196 
## F-statistic: 54.34 on 3 and 11 DF,  p-value: 6.964e-07
# Plot

lm_plot_eSnow <- lm(NO_Snow ~ Elevation, data = loc_stats)

SnowDays_plot <- visualize(lm_plot_eSnow, NO_Snow ~ Elevation, plot = "model") +
    scale_color_manual(values = c("black")) + theme_classic() + labs_pubr() + labs(title = NULL,
    y = "Days without snow", x = NULL) + theme(legend.position = "null")
SnowDays_plot

# Check model fit, residuals etc.

autoplot(lm_NO_Snow) + theme_classic()

shapiro.test(residuals(lm_NO_Snow))
## 
##  Shapiro-Wilk normality test
## 
## data:  residuals(lm_NO_Snow)
## W = 0.95194, p-value = 0.5555

Arrange loc plots

plot_micro <- ggarrange(MeanTemp_plot, SnowDays_plot, Mean_solar, Mean_humid, nrow = 2,
    ncol = 2, labels = "AUTO", common.legend = TRUE, legend = "none", font.label = list(size = 13))

plot_micro

ggsave("plot_micro_final.pdf", plot = plot_micro, path = "../../Figures/Ectotherm_plots/",
    units = "cm", width = 20, height = 20, dpi = 300)
ggsave("plot_microfinal.svg", plot = plot_micro, path = "../../Figures/Ectotherm_plots/",
    units = "cm", width = 20, height = 20, dpi = 300)
ggsave("plot_micro_final.png", plot = plot_micro, path = "../../Figures/Ectotherm_plots/",
    units = "cm", width = 20, height = 20, dpi = 300, bg = "white")

Models and plots for elevation, species and sintopy analysis

Egg development time

# check data distribution
gghistogram(res_ecto_stats$egg_dev, bins = 15) + theme_pubclean()

ggboxplot(res_ecto_stats$egg_dev) + theme_pubclean() + labs(y = NULL, x = NULL)

# Check lm model first
lm_eggDev <- lm(egg_dev ~ Elevation + Species + Loc_type, data = res_ecto_stats)
lm_eggDev_int <- lm(egg_dev ~ Elevation * Species + Loc_type, data = res_ecto_stats)
lm_eggDev_int2 <- lm(egg_dev ~ Elevation * Loc_type + Species, data = res_ecto_stats)
lm_eggDev_int3 <- lm(egg_dev ~ Elevation + Loc_type * Species, data = res_ecto_stats)


compare.fits(egg_dev ~ Elevation | Species + Loc_type, data = res_ecto_stats, lm_eggDev,
    lm_eggDev_int)

compare.fits(egg_dev ~ Elevation | Species + Loc_type, data = res_ecto_stats, lm_eggDev,
    lm_eggDev_int2)

compare.fits(egg_dev ~ Elevation | Species + Loc_type, data = res_ecto_stats, lm_eggDev,
    lm_eggDev_int3)

AIC(lm_eggDev, lm_eggDev_int, lm_eggDev_int2, lm_eggDev_int3)
##                df      AIC
## lm_eggDev       6 149.5496
## lm_eggDev_int   7 151.4352
## lm_eggDev_int2  8 153.3362
## lm_eggDev_int3  8 153.2577
anova(lm_eggDev, lm_eggDev_int, lm_eggDev_int2, lm_eggDev_int3)
## Analysis of Variance Table
## 
## Model 1: egg_dev ~ Elevation + Species + Loc_type
## Model 2: egg_dev ~ Elevation * Species + Loc_type
## Model 3: egg_dev ~ Elevation * Loc_type + Species
## Model 4: egg_dev ~ Elevation + Loc_type * Species
##   Res.Df    RSS Df Sum of Sq      F Pr(>F)
## 1     25 172.14                           
## 2     24 171.49  1   0.65488 0.0881 0.7692
## 3     23 170.92  1   0.56505 0.0760 0.7852
## 4     23 170.47  0   0.44673
summary(lm_eggDev)  ## NO SIGNIFICANT INTERACTIONS
## 
## Call:
## lm(formula = egg_dev ~ Elevation + Species + Loc_type, data = res_ecto_stats)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.2834 -1.4421 -0.6405  0.9118  6.2974 
## 
## Coefficients:
##                           Estimate Std. Error t value Pr(>|t|)    
## (Intercept)              33.939118   2.060944  16.468 6.25e-15 ***
## Elevation                 0.021286   0.001782  11.944 7.94e-12 ***
## SpeciesP. muralis         8.533333   0.958164   8.906 3.15e-09 ***
## Loc_typeMuralis allotopy  2.848066   1.324986   2.150   0.0415 *  
## Loc_typeSintopy          -3.337468   1.392899  -2.396   0.0244 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.624 on 25 degrees of freedom
## Multiple R-squared:  0.9305, Adjusted R-squared:  0.9193 
## F-statistic: 83.62 on 4 and 25 DF,  p-value: 4.264e-14
# summary(lm_eggDev_int) summary(lm_eggDev_int2) summary(lm_eggDev_int3)

# Get summary and p values

visualize(lm_eggDev)

EggDev_plot <- visualize(lm_eggDev, egg_dev ~ Elevation + Loc_type | Species, plot = "model") +
    scale_color_manual(values = c("firebrick", "gold", "navyblue")) + theme_classic() +
    labs_pubr() + labs(title = NULL, y = "Egg development time (days)", x = NULL) +
    theme(strip.text = element_text(face = "italic"), axis.text = element_text(size = 11),
        axis.title = element_text(size = 12, face = "bold")) + facet_wrap(~Species)

EggDev_plot

# Check model fit, residuals etc.

autoplot(lm_eggDev) + theme_classic()

shapiro.test(residuals(lm_eggDev))
## 
##  Shapiro-Wilk normality test
## 
## data:  residuals(lm_eggDev)
## W = 0.94739, p-value = 0.1438
# Check comparisons
summary(glht(lm_eggDev, linfct = mcp(Loc_type = "Tukey")))
## 
##   Simultaneous Tests for General Linear Hypotheses
## 
## Multiple Comparisons of Means: Tukey Contrasts
## 
## 
## Fit: lm(formula = egg_dev ~ Elevation + Species + Loc_type, data = res_ecto_stats)
## 
## Linear Hypotheses:
##                                           Estimate Std. Error t value Pr(>|t|)
## Muralis allotopy - Horvathi allotopy == 0    2.848      1.325   2.150   0.0996
## Sintopy - Horvathi allotopy == 0            -3.337      1.393  -2.396   0.0607
## Sintopy - Muralis allotopy == 0             -6.186      1.181  -5.236   <0.001
##                                              
## Muralis allotopy - Horvathi allotopy == 0 .  
## Sintopy - Horvathi allotopy == 0          .  
## Sintopy - Muralis allotopy == 0           ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## (Adjusted p values reported -- single-step method)

Lifespan

# check data
gghistogram(res_ecto_stats$LifeSpan, bins = 4)

ggboxplot(res_ecto_stats$LifeSpan)

# Check lm model first



lm_Lifespan <- lm(LifeSpan ~ Elevation + Species + Loc_type, data = res_ecto_stats)
lm_Lifespan_int <- lm(LifeSpan ~ Elevation * Species + Loc_type, data = res_ecto_stats)
lm_Lifespan_int2 <- lm(LifeSpan ~ Elevation * Loc_type + Species, data = res_ecto_stats)
lm_Lifespan_int3 <- lm(LifeSpan ~ Elevation + Loc_type * Species, data = res_ecto_stats)


compare.fits(LifeSpan ~ Elevation | Species + Loc_type, data = res_ecto_stats, lm_Lifespan,
    lm_Lifespan_int)

compare.fits(LifeSpan ~ Elevation | Species + Loc_type, data = res_ecto_stats, lm_Lifespan,
    lm_Lifespan_int2)

compare.fits(LifeSpan ~ Elevation | Species + Loc_type, data = res_ecto_stats, lm_Lifespan,
    lm_Lifespan_int3)

AIC(lm_Lifespan, lm_Lifespan_int, lm_Lifespan_int2, lm_Lifespan_int3)
##                  df      AIC
## lm_Lifespan       6 24.40601
## lm_Lifespan_int   7 25.53875
## lm_Lifespan_int2  8 26.08489
## lm_Lifespan_int3  8 27.64341
anova(lm_Lifespan, lm_Lifespan_int, lm_Lifespan_int2, lm_Lifespan_int3)
## Analysis of Variance Table
## 
## Model 1: LifeSpan ~ Elevation + Species + Loc_type
## Model 2: LifeSpan ~ Elevation * Species + Loc_type
## Model 3: LifeSpan ~ Elevation * Loc_type + Species
## Model 4: LifeSpan ~ Elevation + Loc_type * Species
##   Res.Df    RSS Df Sum of Sq      F Pr(>F)
## 1     25 2.6561                           
## 2     24 2.5804  1  0.075685 0.7081 0.4087
## 3     23 2.4583  1  0.122070 1.1421 0.2963
## 4     23 2.5894  0 -0.131088
summary(lm_Lifespan)  ## NO SIGNIFICANT INTERACTIONS, CHECKED MODELS BY AIC AND COMPARED FITS
## 
## Call:
## lm(formula = LifeSpan ~ Elevation + Species + Loc_type, data = res_ecto_stats)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.56118 -0.28673  0.01384  0.33310  0.42537 
## 
## Coefficients:
##                            Estimate Std. Error t value Pr(>|t|)    
## (Intercept)               6.9824824  0.2560040  27.275  < 2e-16 ***
## Elevation                 0.0012542  0.0002214   5.666 6.73e-06 ***
## SpeciesP. muralis         1.0666667  0.1190201   8.962 2.79e-09 ***
## Loc_typeMuralis allotopy -0.0670286  0.1645856  -0.407   0.6873    
## Loc_typeSintopy          -0.3718992  0.1730215  -2.149   0.0415 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.326 on 25 degrees of freedom
## Multiple R-squared:  0.8577, Adjusted R-squared:  0.8349 
## F-statistic: 37.67 on 4 and 25 DF,  p-value: 3.046e-10
# summary(lm_Lifespan_int) summary(lm_Lifespan_int2) summary(lm_Lifespan_int3)



# Get summary and p values

visualize(lm_Lifespan_int2)

Lifespan_plot <- visualize(lm_Lifespan, LifeSpan ~ Elevation + Loc_type | Species,
    plot = "model") + scale_color_manual(values = c("firebrick", "gold", "navyblue")) +
    theme_classic() + labs_pubr() + labs(title = NULL, y = "Lifespan (years)", x = NULL) +
    theme(strip.text = element_text(face = "italic"), axis.text = element_text(size = 11),
        axis.title = element_text(size = 12, face = "bold")) + facet_wrap(~Species)
Lifespan_plot

# Check model fit, residuals etc.

autoplot(lm_Lifespan_int2) + theme_classic()

shapiro.test(residuals(lm_Lifespan_int2))
## 
##  Shapiro-Wilk normality test
## 
## data:  residuals(lm_Lifespan_int2)
## W = 0.95247, p-value = 0.1968
# Check comparisons

summary(glht(lm_Lifespan, linfct = mcp(Loc_type = "Tukey")))
## 
##   Simultaneous Tests for General Linear Hypotheses
## 
## Multiple Comparisons of Means: Tukey Contrasts
## 
## 
## Fit: lm(formula = LifeSpan ~ Elevation + Species + Loc_type, data = res_ecto_stats)
## 
## Linear Hypotheses:
##                                           Estimate Std. Error t value Pr(>|t|)
## Muralis allotopy - Horvathi allotopy == 0 -0.06703    0.16459  -0.407   0.9126
## Sintopy - Horvathi allotopy == 0          -0.37190    0.17302  -2.149   0.0997
## Sintopy - Muralis allotopy == 0           -0.30487    0.14673  -2.078   0.1143
##                                            
## Muralis allotopy - Horvathi allotopy == 0  
## Sintopy - Horvathi allotopy == 0          .
## Sintopy - Muralis allotopy == 0            
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## (Adjusted p values reported -- single-step method)

Years reproducing

# check data
gghistogram(res_ecto_stats$Years_repro, bins = 8)

ggboxplot(res_ecto_stats$Years_repro)

# Check lm model first
lm_YearsRepro_noLoc <- lm(Years_repro ~ Elevation + Species, data = res_ecto_stats)
lm_YearsRepro <- lm(Years_repro ~ Elevation + Species + Loc_type, data = res_ecto_stats)
lm_YearsRepro_int <- lm(Years_repro ~ Elevation * Species + Loc_type, data = res_ecto_stats)
lm_YearsRepro_int2 <- lm(Years_repro ~ Elevation * Loc_type + Species, data = res_ecto_stats)
lm_YearsRepro_int3 <- lm(Years_repro ~ Elevation + Loc_type * Species, data = res_ecto_stats)



compare.fits(Years_repro ~ Elevation | Species + Loc_type, data = res_ecto_stats,
    lm_YearsRepro, lm_YearsRepro_int)

compare.fits(Years_repro ~ Elevation | Species + Loc_type, data = res_ecto_stats,
    lm_YearsRepro, lm_YearsRepro_int2)

compare.fits(Years_repro ~ Elevation | Species + Loc_type, data = res_ecto_stats,
    lm_YearsRepro, lm_YearsRepro_int3)

AIC(lm_YearsRepro, lm_YearsRepro_int, lm_YearsRepro_int2, lm_YearsRepro_int3, lm_YearsRepro_noLoc)
##                     df      AIC
## lm_YearsRepro        6 79.17173
## lm_YearsRepro_int    7 79.64740
## lm_YearsRepro_int2   8 79.43249
## lm_YearsRepro_int3   8 82.80551
## lm_YearsRepro_noLoc  4 78.61733
anova(lm_YearsRepro_noLoc, lm_YearsRepro, lm_YearsRepro_int, lm_YearsRepro_int2,
    lm_YearsRepro_int3)
## Analysis of Variance Table
## 
## Model 1: Years_repro ~ Elevation + Species
## Model 2: Years_repro ~ Elevation + Species + Loc_type
## Model 3: Years_repro ~ Elevation * Species + Loc_type
## Model 4: Years_repro ~ Elevation * Loc_type + Species
## Model 5: Years_repro ~ Elevation + Loc_type * Species
##   Res.Df    RSS Df Sum of Sq      F Pr(>F)
## 1     27 18.490                           
## 2     25 16.484  2   2.00623 1.5854 0.2264
## 3     24 15.667  1   0.81663 1.2907 0.2676
## 4     23 14.552  1   1.11505 1.7624 0.1974
## 5     23 16.284  0  -1.73168
summary(lm_YearsRepro_noLoc)  ## OPT FOR SIMPLER MODEL
## 
## Call:
## lm(formula = Years_repro ~ Elevation + Species, data = res_ecto_stats)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.8976 -0.2866  0.1232  0.5074  1.0660 
## 
## Coefficients:
##                     Estimate Std. Error t value Pr(>|t|)    
## (Intercept)        4.3575515  0.4159431  10.476 5.18e-11 ***
## Elevation         -0.0017666  0.0004644  -3.804 0.000741 ***
## SpeciesP. muralis  0.8000000  0.3021734   2.647 0.013371 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8275 on 27 degrees of freedom
## Multiple R-squared:  0.4431, Adjusted R-squared:  0.4018 
## F-statistic: 10.74 on 2 and 27 DF,  p-value: 0.0003701
# summary(lm_YearsRepro_int) summary(lm_YearsRepro_int2)
# summary(lm_YearsRepro_int3)


# Get summary and p values


visualize(lm_YearsRepro_noLoc)

YearsRepro_plot <- visualize(lm_YearsRepro_noLoc, Years_repro ~ Elevation | Species,
    plot = "model") + scale_color_manual(values = c("black")) + theme_classic() +
    labs_pubr() + labs(title = NULL, y = "Years reproducing", x = NULL) + theme(strip.background = element_blank(),
    strip.text.x = element_blank(), axis.text = element_text(size = 11), axis.title = element_text(size = 12,
        face = "bold")) + facet_wrap(~Species)

YearsRepro_plot

# Check model fit, residuals etc.

autoplot(lm_YearsRepro) + theme_classic()

shapiro.test(residuals(lm_YearsRepro))
## 
##  Shapiro-Wilk normality test
## 
## data:  residuals(lm_YearsRepro)
## W = 0.80519, p-value = 8.164e-05

Yearly basking time

# check data
gghistogram(res_ecto_stats$Bask_year, bins = 8)

ggboxplot(res_ecto_stats$Bask_year)

# Check lm model first
lm_BaskYear <- lm(Bask_year ~ Elevation + Species + Loc_type, data = res_ecto_stats)
lm_BaskYear_int <- lm(Bask_year ~ Elevation * Species + Loc_type, data = res_ecto_stats)
lm_BaskYear_int2 <- lm(Bask_year ~ Elevation * Loc_type + Species, data = res_ecto_stats)
lm_BaskYear_int3 <- lm(Bask_year ~ Elevation + Loc_type * Species, data = res_ecto_stats)

compare.fits(Bask_year ~ Elevation | Species + Loc_type, data = res_ecto_stats, lm_BaskYear,
    lm_BaskYear_int)

compare.fits(Bask_year ~ Elevation | Species + Loc_type, data = res_ecto_stats, lm_BaskYear,
    lm_BaskYear_int2)

compare.fits(Bask_year ~ Elevation | Species + Loc_type, data = res_ecto_stats, lm_BaskYear,
    lm_BaskYear_int3)

AIC(lm_BaskYear, lm_BaskYear_int, lm_BaskYear_int2, lm_BaskYear_int3)
##                  df      AIC
## lm_BaskYear       6 366.5616
## lm_BaskYear_int   7 368.5616
## lm_BaskYear_int2  8 368.9511
## lm_BaskYear_int3  8 370.5466
anova(lm_BaskYear, lm_BaskYear_int, lm_BaskYear_int2, lm_BaskYear_int3)
## Analysis of Variance Table
## 
## Model 1: Bask_year ~ Elevation + Species + Loc_type
## Model 2: Bask_year ~ Elevation * Species + Loc_type
## Model 3: Bask_year ~ Elevation * Loc_type + Species
## Model 4: Bask_year ~ Elevation + Loc_type * Species
##   Res.Df    RSS Df Sum of Sq      F Pr(>F)
## 1     25 238480                           
## 2     24 238480  1       0.2 0.0000 0.9965
## 3     23 226015  1   12464.7 1.2684 0.2717
## 4     23 238361  0  -12345.7
summary(lm_BaskYear)  ## NO SIGNIFICANT INTERACTIONS
## 
## Call:
## lm(formula = Bask_year ~ Elevation + Species + Loc_type, data = res_ecto_stats)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -181.902  -62.389   -4.095   74.524  158.334 
## 
## Coefficients:
##                            Estimate Std. Error t value Pr(>|t|)    
## (Intercept)              1846.36601   76.70997  24.069  < 2e-16 ***
## Elevation                  -0.34636    0.06633  -5.222 2.10e-05 ***
## SpeciesP. muralis        -361.50730   35.66363 -10.137 2.44e-10 ***
## Loc_typeMuralis allotopy  -33.78520   49.31702  -0.685   0.4996    
## Loc_typeSintopy           122.38856   51.84480   2.361   0.0263 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 97.67 on 25 degrees of freedom
## Multiple R-squared:  0.8714, Adjusted R-squared:  0.8508 
## F-statistic: 42.34 on 4 and 25 DF,  p-value: 8.748e-11
# summary(lm_BaskYear_int) summary(lm_BaskYear_int2) summary(lm_BaskYear_int3)


# Get summary and p values

visualize(lm_BaskYear)

Basking_plot <- visualize(lm_BaskYear, Bask_year ~ Elevation + Loc_type | Species,
    plot = "model") + scale_color_manual(values = c("firebrick", "gold", "navyblue")) +
    theme_classic() + labs_pubr() + labs(title = NULL, y = "Mean yearly basking time",
    x = NULL) + theme(strip.background = element_blank(), strip.text.x = element_blank(),
    axis.text = element_text(size = 11), axis.title = element_text(size = 12, face = "bold")) +
    facet_wrap(~Species)

Basking_plot

# Check model fit, residuals etc.

autoplot(lm_BaskYear) + theme_classic()

shapiro.test(residuals(lm_BaskYear))
## 
##  Shapiro-Wilk normality test
## 
## data:  residuals(lm_BaskYear)
## W = 0.97735, p-value = 0.7517
# Check comparisons

summary(glht(lm_BaskYear, linfct = mcp(Loc_type = "Tukey")))
## 
##   Simultaneous Tests for General Linear Hypotheses
## 
## Multiple Comparisons of Means: Tukey Contrasts
## 
## 
## Fit: lm(formula = Bask_year ~ Elevation + Species + Loc_type, data = res_ecto_stats)
## 
## Linear Hypotheses:
##                                           Estimate Std. Error t value Pr(>|t|)
## Muralis allotopy - Horvathi allotopy == 0   -33.79      49.32  -0.685  0.77345
## Sintopy - Horvathi allotopy == 0            122.39      51.84   2.361  0.06532
## Sintopy - Muralis allotopy == 0             156.17      43.97   3.552  0.00414
##                                             
## Muralis allotopy - Horvathi allotopy == 0   
## Sintopy - Horvathi allotopy == 0          . 
## Sintopy - Muralis allotopy == 0           **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## (Adjusted p values reported -- single-step method)

Forage time

# check data
gghistogram(res_ecto_stats$Forage_year, bins = 8)

ggboxplot(res_ecto_stats$Forage_year)

# Check lm model first

lm_ForageYear <- lm(Forage_year ~ Elevation + Species + Loc_type, data = res_ecto_stats)
lm_ForageYear_int <- lm(Forage_year ~ Elevation * Species + Loc_type, data = res_ecto_stats)
lm_ForageYear_int2 <- lm(Forage_year ~ Elevation * Loc_type + Species, data = res_ecto_stats)
lm_ForageYear_int3 <- lm(Forage_year ~ Elevation + Loc_type * Species, data = res_ecto_stats)


compare.fits(Forage_year ~ Elevation | Species + Loc_type, data = res_ecto_stats,
    lm_ForageYear, lm_ForageYear_int)

compare.fits(Forage_year ~ Elevation | Species + Loc_type, data = res_ecto_stats,
    lm_ForageYear, lm_ForageYear_int2)

compare.fits(Forage_year ~ Elevation | Species + Loc_type, data = res_ecto_stats,
    lm_ForageYear, lm_ForageYear_int3)

AIC(lm_ForageYear, lm_ForageYear_int, lm_ForageYear_int2, lm_ForageYear_int3)
##                    df      AIC
## lm_ForageYear       6 303.6498
## lm_ForageYear_int   7 302.5191
## lm_ForageYear_int2  8 304.0072
## lm_ForageYear_int3  8 305.6708
anova(lm_ForageYear, lm_ForageYear_int, lm_ForageYear_int2, lm_ForageYear_int3)
## Analysis of Variance Table
## 
## Model 1: Forage_year ~ Elevation + Species + Loc_type
## Model 2: Forage_year ~ Elevation * Species + Loc_type
## Model 3: Forage_year ~ Elevation * Loc_type + Species
## Model 4: Forage_year ~ Elevation + Loc_type * Species
##   Res.Df   RSS Df Sum of Sq      F Pr(>F)
## 1     25 29289                           
## 2     24 26387  1   2902.51 2.5735 0.1223
## 3     23 25941  1    446.37 0.3958 0.5355
## 4     23 27420  0  -1479.12
summary(lm_ForageYear)  ## NO SIGNIFICANT INTERACTION
## 
## Call:
## lm(formula = Forage_year ~ Elevation + Species + Loc_type, data = res_ecto_stats)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -71.75 -19.80   1.03  19.75  51.40 
## 
## Coefficients:
##                           Estimate Std. Error t value Pr(>|t|)    
## (Intercept)              482.33872   26.88320  17.942 8.61e-16 ***
## Elevation                 -0.16908    0.02325  -7.274 1.27e-07 ***
## SpeciesP. muralis         94.91675   12.49840   7.594 5.99e-08 ***
## Loc_typeMuralis allotopy -18.68100   17.28327  -1.081   0.2901    
## Loc_typeSintopy           41.14568   18.16913   2.265   0.0325 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 34.23 on 25 degrees of freedom
## Multiple R-squared:  0.8691, Adjusted R-squared:  0.8482 
## F-statistic:  41.5 on 4 and 25 DF,  p-value: 1.086e-10
# summary(lm_ForageYear_int) summary(lm_ForageYear_int2)
# summary(lm_ForageYear_int3)


# Plot

visualize(lm_ForageYear)

Forage_plot <- visualize(lm_ForageYear, Forage_year ~ Elevation + Loc_type | Species,
    plot = "model") + scale_color_manual(values = c("firebrick", "gold", "navyblue")) +
    theme_classic() + labs_pubr() + labs(title = NULL, y = "Mean yearly foraging time",
    x = "Elevation (m)") + theme(strip.background = element_blank(), strip.text.x = element_blank(),
    axis.text = element_text(size = 11), axis.title = element_text(size = 12, face = "bold")) +
    facet_wrap(~Species)

Forage_plot

# Check model fit, residuals etc.

autoplot(lm_ForageYear) + theme_classic()

shapiro.test(residuals(lm_ForageYear))
## 
##  Shapiro-Wilk normality test
## 
## data:  residuals(lm_ForageYear)
## W = 0.97172, p-value = 0.5872
# Check comparisons

summary(glht(lm_ForageYear, linfct = mcp(Loc_type = "Tukey")))
## 
##   Simultaneous Tests for General Linear Hypotheses
## 
## Multiple Comparisons of Means: Tukey Contrasts
## 
## 
## Fit: lm(formula = Forage_year ~ Elevation + Species + Loc_type, data = res_ecto_stats)
## 
## Linear Hypotheses:
##                                           Estimate Std. Error t value Pr(>|t|)
## Muralis allotopy - Horvathi allotopy == 0   -18.68      17.28  -1.081  0.53326
## Sintopy - Horvathi allotopy == 0             41.15      18.17   2.265  0.07934
## Sintopy - Muralis allotopy == 0              59.83      15.41   3.883  0.00186
##                                             
## Muralis allotopy - Horvathi allotopy == 0   
## Sintopy - Horvathi allotopy == 0          . 
## Sintopy - Muralis allotopy == 0           **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## (Adjusted p values reported -- single-step method)

Fecundity per year

# check data distribution
gghistogram(res_ecto_stats$Fecundity_year, bins = 15)

ggboxplot(res_ecto_stats$Fecundity_year)

# Check lm model first

lm_FecundityYear <- lm(Fecundity_year ~ Elevation + Species + Loc_type, data = res_ecto_stats)
lm_FecundityYear_int <- lm(Fecundity_year ~ Elevation * Species + Loc_type, data = res_ecto_stats)
lm_FecundityYear_int2 <- lm(Fecundity_year ~ Elevation * Loc_type + Species, data = res_ecto_stats)
lm_FecundityYear_int3 <- lm(Fecundity_year ~ Elevation + Loc_type * Species, data = res_ecto_stats)



compare.fits(Fecundity_year ~ Elevation | Species + Loc_type, data = res_ecto_stats,
    lm_FecundityYear, lm_FecundityYear_int)

compare.fits(Fecundity_year ~ Elevation | Species + Loc_type, data = res_ecto_stats,
    lm_FecundityYear, lm_FecundityYear_int2)

compare.fits(Fecundity_year ~ Elevation | Species + Loc_type, data = res_ecto_stats,
    lm_FecundityYear, lm_FecundityYear_int3)

AIC(lm_FecundityYear, lm_FecundityYear_int, lm_FecundityYear_int2, lm_FecundityYear_int3)
##                       df      AIC
## lm_FecundityYear       6 36.27660
## lm_FecundityYear_int   7 29.19254
## lm_FecundityYear_int2  8 37.83507
## lm_FecundityYear_int3  8 34.53056
anova(lm_FecundityYear, lm_FecundityYear_int, lm_FecundityYear_int2, lm_FecundityYear_int3)
## Analysis of Variance Table
## 
## Model 1: Fecundity_year ~ Elevation + Species + Loc_type
## Model 2: Fecundity_year ~ Elevation * Species + Loc_type
## Model 3: Fecundity_year ~ Elevation * Loc_type + Species
## Model 4: Fecundity_year ~ Elevation + Loc_type * Species
##   Res.Df    RSS Df Sum of Sq      F  Pr(>F)  
## 1     25 3.9454                              
## 2     24 2.9146  1   1.03074 6.5183 0.01778 *
## 3     23 3.6370  1  -0.72237                 
## 4     23 3.2576  0   0.37934                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# summary(lm_FecundityYear)
summary(lm_FecundityYear_int)  ## significant interaction
## 
## Call:
## lm(formula = Fecundity_year ~ Elevation * Species + Loc_type, 
##     data = res_ecto_stats)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.5756 -0.2397  0.0506  0.2124  0.7352 
## 
## Coefficients:
##                               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                  1.4635603  0.3122470   4.687  9.2e-05 ***
## Elevation                   -0.0008098  0.0003070  -2.638  0.01441 *  
## SpeciesP. muralis            1.6057455  0.3263897   4.920  5.1e-05 ***
## Loc_typeMuralis allotopy    -0.3450186  0.1759648  -1.961  0.06162 .  
## Loc_typeSintopy              0.2443910  0.1849840   1.321  0.19891    
## Elevation:SpeciesP. muralis -0.0011395  0.0003911  -2.913  0.00762 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3485 on 24 degrees of freedom
## Multiple R-squared:  0.8179, Adjusted R-squared:  0.7799 
## F-statistic: 21.56 on 5 and 24 DF,  p-value: 3.666e-08
# summary(lm_FecundityYear_int2) summary(lm_FecundityYear_int3)



# Plot
visualize(lm_FecundityYear_int)

Fecundity_plot <- visualize(lm_FecundityYear_int, Fecundity_year ~ Elevation + Loc_type |
    Species, plot = "model") + scale_color_manual(values = c("firebrick", "gold",
    "navyblue")) + theme_classic() + labs_pubr() + labs(title = NULL, y = "Yearly fecundity",
    x = "Elevation (m)") + theme(strip.background = element_blank(), strip.text.x = element_blank(),
    axis.text = element_text(size = 11), axis.title = element_text(size = 12, face = "bold")) +
    facet_wrap(~Species)



Fecundity_plot

# Check model fit, residuals etc.

autoplot(lm_FecundityYear_int) + theme_classic()

shapiro.test(residuals(lm_FecundityYear_int))
## 
##  Shapiro-Wilk normality test
## 
## data:  residuals(lm_FecundityYear_int)
## W = 0.97448, p-value = 0.6674
# Check comparisons
summary(glht(lm_FecundityYear_int, linfct = mcp(Loc_type = "Tukey")))
## 
##   Simultaneous Tests for General Linear Hypotheses
## 
## Multiple Comparisons of Means: Tukey Contrasts
## 
## 
## Fit: lm(formula = Fecundity_year ~ Elevation * Species + Loc_type, 
##     data = res_ecto_stats)
## 
## Linear Hypotheses:
##                                           Estimate Std. Error t value Pr(>|t|)
## Muralis allotopy - Horvathi allotopy == 0  -0.3450     0.1760  -1.961   0.1431
## Sintopy - Horvathi allotopy == 0            0.2444     0.1850   1.321   0.3963
## Sintopy - Muralis allotopy == 0             0.5894     0.1569   3.757   0.0027
##                                             
## Muralis allotopy - Horvathi allotopy == 0   
## Sintopy - Horvathi allotopy == 0            
## Sintopy - Muralis allotopy == 0           **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## (Adjusted p values reported -- single-step method)

Arrange plots

plot_ecto <- ggarrange(EggDev_plot, Lifespan_plot, YearsRepro_plot, Basking_plot,
    Forage_plot, Fecundity_plot, nrow = 3, ncol = 2, labels = "AUTO", common.legend = FALSE,
    legend = "none", font.label = list(size = 13, color = "black", face = "bold"))

plot_ecto

ggsave("plot_ecto_final.pdf", plot = plot_ecto, path = "../../Figures/Ectotherm_plots/",
    units = "cm", width = 20, height = 20, dpi = 300)
ggsave("plot_ecto_final.svg", plot = plot_ecto, path = "../../Figures/Ectotherm_plots/",
    units = "cm", width = 20, height = 20, dpi = 300)
ggsave("plot_ecto_final.png", plot = plot_ecto, path = "../../Figures/Ectotherm_plots/",
    units = "cm", width = 20, height = 20, dpi = 300, bg = "white")